﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.BusinessObject.Product;
using Axis.Dao.Product;

namespace Sotipha.Web.Views.Home
{
    public partial class ucProductSlideShow : System.Web.UI.UserControl
    {
        CProductDao coreProductGroup = new CProductDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            CProductDao coreProductGroup = new CProductDao();
            IList<CProduct> listProduct = coreProductGroup.GetProductByCondition("<InputValue Context=\"SlideShow\"/>");
            int totalRecords = coreProductGroup.LastOutputValue.TotalRows;
            string ImageProduct = "";
            string IntroProduct = "";
            string PatternImage="<a href=\"{2}\"><img src=\"{0}\" alt=\"\" title=\"#htmlcaption{1}\" /></a> ";
            string PatternIntro="<div id=\"htmlcaption{0}\" class=\"nivo-html-caption\">"+
                                "<b><a href=\"{3}\">{1}</a></b><br />"+
                                "<div>{2}</div>"+
                              "</div>";
            if (Session["lang"].ToString() == "vi")
            {
                foreach (var item in listProduct) {
                    var Link = BuildLink(item);
                    ImageProduct += string.Format(PatternImage, item.LargeImage, item.ID, Link);
                    IntroProduct += string.Format(PatternIntro, item.ID, item.Name_VN, item.Intro_VN, Link);
                }
            }
            else {
                foreach (var item in listProduct)
                {
                    var Link = BuildLink(item);
                    ImageProduct += string.Format(PatternImage, item.LargeImage, item.ID, Link);
                    IntroProduct += string.Format(PatternIntro, item.ID, item.Name_EN, item.Intro_EN, Link);
                }
            }
            ltrImage.Text = ImageProduct;
            ltrIntro.Text = IntroProduct;
        }
        public string BuildLink(CProduct Item) {
            string Result = "";
            switch (Item.ProductTypeID)
            { 
                case 1:
                    Result = "../Towntalk/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 2:
                    Result = "../Lacquerware/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 3:
                    Result = "../Gifts/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 4:
                    Result = "../Sale/ProductDetail.aspx?ID=" + Item.ID;
                    break;  
            }
            return Result;
        }
    }
}